package com.motherchild.admin.service.impl;

import com.motherchild.admin.dto.InventoryRecordDTO;
import com.motherchild.admin.mapper.InventoryMapper;
import com.motherchild.admin.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class InventoryServiceImpl implements InventoryService {

    @Autowired
    private InventoryMapper inventoryMapper;

    @Override
    public List<InventoryRecordDTO> getInventoryRecords() {
        return inventoryMapper.selectInventoryRecords();
    }

    @Override
    public List<InventoryRecordDTO> getStockRecordList() {
        return inventoryMapper.getStockRecordList();
    }

    @Override
    public void addInventoryRecord(InventoryRecordDTO recordDTO) {
        String productById = inventoryMapper.getProductById(recordDTO.getProductId());
        recordDTO.setName(productById);

            //插入记录表
            inventoryMapper.insertInventoryRecord(recordDTO);
            //加减库存（1入2出3盘点）
            if (recordDTO.getType() == 2){
                inventoryMapper.updateStock(recordDTO);
            }else if (recordDTO.getType() == 1){
                inventoryMapper.updateStock1(recordDTO);
            }


    }

    @Override
    public List<InventoryRecordDTO> getInventoryRescords(String name) {
        return inventoryMapper.selectInventorysRecords(name);
    }

    @Override
    public List<InventoryRecordDTO> getRescords(String name) {
        return inventoryMapper.selectRecords(name);
    }
}